const { Sequelize, DataTypes } = require('sequelize')
const md5 = require('md5')

// 建立连接
const sequelize = new Sequelize(
    'node_test', 'root', 'guzhan321',
    {
        host: 'localhost',
        dialect: 'mysql', // 数据库方言
    }
)

// 定义模型

const User = sequelize.define(
    'User', {
        username: { type: DataTypes.STRING },
        password:{
            type: DataTypes.STRING,
            set(v) {
                this.setDataValue('password', md5(v))
            }
        }
    }
); 

sequelize.sync({ force: true })

module.exports = User
